package com.zelin.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 功能: 配置分页插件
 * 参数:
 * 返回值:
 * 时间: 2021/7/23 15:13
 */
@Configuration
@MapperScan("com.zelin.dao")
@EnableTransactionManagement
public class MybatisPlusConfig {

    // 最新版(配置分页插件)
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptorPage() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }


    // 配置乐观锁
    // @Bean
    // public MybatisPlusInterceptor mybatisPlusInterceptorLock() {
    //     MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
    //     interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
    //     return interceptor;
    // }
}